package com.woniuxy.hospital.controller;


import com.woniuxy.hospital.entity.HplDepartment;
import com.woniuxy.hospital.entity.HplDoctor;
import com.woniuxy.hospital.hplutils.ResponseEntity;
import com.woniuxy.hospital.hplutils.ResponseState;
import com.woniuxy.hospital.service.IHplDepartmentService;
import com.woniuxy.hospital.service.IHplDoctorService;
import com.woniuxy.hospital.service.IHplTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-08-12
 */
@CrossOrigin
@RestController
@RequestMapping("/hpl-doctor")
public class HplDoctorController {

    @Autowired
    private IHplDoctorService iHplDoctorService;

    @Autowired
    private IHplDepartmentService iHplDepartmentService;

    @Autowired
    private IHplTitleService iHplTitleService;
    /**
     * 得到所有的医生
     * @return 返回所有医生
     */
    @GetMapping("getAll")
    public ResponseEntity<List<HplDoctor>> getAll(){
        List<HplDoctor> doctors = iHplDoctorService.list();
        for (HplDoctor doctor : doctors) {
         doctor.setDepName(iHplDepartmentService.getById(doctor.getDepId()).getName());
        }
        for (HplDoctor doctor : doctors) {
            doctor.setTitleName(iHplTitleService.getById(doctor.getTitleId()).getName());
        }
        ResponseEntity<List<HplDoctor>> responseEntity = new ResponseEntity<>(ResponseState.SUCCESS,"ok");
        responseEntity.setData(doctors);
        return responseEntity;
    }

    /**
     * 按条件查询医生
     * @return 符合条件的医生
     */
    @PostMapping("getByCondition")
    public ResponseEntity<List<HplDoctor>> getByCondition(@RequestBody HplDoctor hplDoctor){
        List<HplDoctor> doctors = iHplDoctorService.getByCondition(hplDoctor);
        ResponseEntity<List<HplDoctor>> responseEntity = new ResponseEntity<>(ResponseState.SUCCESS,"ok");
        responseEntity.setData(doctors);
        return responseEntity;
    }
}

